package com.gxxy.spring.kp04_integration.cls02_transaction.s02_annotation;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

@Repository
public class AccountDaoImpl implements IAccountDao {
	private JdbcTemplate jdbcTemplate;
	@Autowired
	public void setDataSource(DataSource dataSource) {
		this.jdbcTemplate = new JdbcTemplate(dataSource);
	}
	@Override
	public void transferIn(Long inId, Double balance) {
		jdbcTemplate.update("UPDATE bankuser SET balance "
				+ "= balance + ? WHERE id = ?", balance, inId);
	}
	@Override
	public void transferOut(Long outId, Double balance) {
		jdbcTemplate.update("UPDATE bankuser SET balance "
				+ "= balance - ? WHERE id = ?", balance, outId);
	}
}
